<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>生成方案管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    // loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

        });

        function changeProjectId() {
            var projectId = $("#projectId").val();

            // 清空包路径
            $("#basePackage").val("");

            // 重置moduleId下拉框的选择项
            $("#moduleId").val("");
            $("#moduleId").trigger("change");
            $("#moduleId").empty();

            // 重新获取moduleId下拉框内容
            if ("" != projectId) {
                $.get("${ctx}/gen/genScheme/ajaxGetProjectModules?projectId=" + projectId,
                    function (data, status) {

                        for (var i = 0; i < data.length; i++) {
                            $("#moduleId").append("<option value='" + data[i].id + "'>" + data[i].moduleCode + "</option>");
                        }
                    });
            }
        }

        function changeModuleId() {
            var moduleId = $("#moduleId").val();
            var projectId = $("#projectId").val();

            // 清空包路径
            $("#basePackage").val("");

            // 重新获取基础包路径
            if ("" != moduleId && "nothing" != moduleId) {
                $.get("${ctx}/gen/genScheme/ajaxGetModuleBasePackage?moduleId=" + moduleId,
                    function (data, status) {
                        $("#basePackage").val(data);
                    });
            }else{
                $.get("${ctx}/gen/genScheme/ajaxGetProjectBasePackage?projectId=" + projectId,
                    function (data, status) {
                        $("#basePackage").val(data);
                    });
            }
        }

        function changeGenTableId() {
            var tableId = $("#genTableId").val();

            // 清空功能名
            $("#functionName").val("");

            // 重新获取功能名
            if ("" != tableId) {
                $.get("${ctx}/gen/genScheme/ajaxGetTableDesc?tableId=" + tableId,
                    function (data, status) {
                        $("#functionName").val(data);
                    });
            }
        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/gen/genScheme/">生成方案列表</a></li>
    <li class="active"><a href="${ctx}/gen/genScheme/form?id=${genScheme.id}">生成方案查看</a></li>
</ul>
<br/>
<form:form id="inputForm" modelAttribute="genScheme" action="${ctx}/gen/genScheme/downLoadZip" method="post" class="form-horizontal">
    <form:hidden path="id"/>
    <sys:message content="${message}"/>
    <div class="control-group hide">
        <label class="control-label">方案名称:</label>
        <div class="controls">
            <form:input path="name" htmlEscape="false" maxlength="200" class="required"/>
            <span class="help-inline"></span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">项目&模块:</label>
        <div class="controls">
            <form:select path="projectId" class="required input-xlarge" onchange="changeProjectId()">
                <form:option value="" label="请选择"/>
                <form:options items="${projectList}" itemLabel="code" itemValue="id" htmlEscape="false"/>
            </form:select>
            <form:select path="moduleId" class="required input-xlarge" onchange="changeModuleId()">
                <form:option value="nothing" label="无"/>
            </form:select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">模板:</label>
        <div class="controls">
            <form:select path="templateId" class="required input-xlarge">
                <form:option value="" label="请选择"/>
                <form:options items="${templateList}" itemLabel="name" itemValue="id" htmlEscape="false"/>
            </form:select>
            <span class="help-inline" style="color:red">*</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">业务表:</label>
        <div class="controls">
            <form:select path="genTableId" class="required input-xlarge" onchange="changeGenTableId()">
                <form:option value="" label="请选择"/>
                <form:options items="${tableList}" itemLabel="nameAndComments" itemValue="id" htmlEscape="false"/>
            </form:select>
            <span class="help-inline" style="color:red">*</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">包路径:</label>
        <div class="controls">
            <form:input path="basePackage" htmlEscape="false" maxlength="500" class="required input-xlarge"/>
            <span class="help-inline" style="color:red">*</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">功能名:</label>
        <div class="controls">
            <form:input path="functionName" htmlEscape="false" maxlength="500" class="required input-xlarge"/>
            <span class="help-inline" style="color:red">*</span>
        </div>
    </div>
    <div class="control-group hide">
        <label class="control-label">导入导出:</label>
        <div class="controls">
            <form:checkboxes path="importExport" items="${importExport}" itemLabel="itemName" itemValue="itemCode" htmlEscape="false" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">作者:</label>
        <div class="controls">
            <form:input path="author" htmlEscape="false" maxlength="500" class="required input-xlarge"/>
            <span class="help-inline" style="color:red">*</span>
        </div>
    </div>
    <div class="form-actions">
        <shiro:hasPermission name="gen:genScheme:edit">
            <input id="btnSubmit" class="btn btn-primary" type="submit" value="生成代码"/>&nbsp;
        </shiro:hasPermission>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
</body>
</html>
